﻿using MediatR;
using T.Vehicleservice.API.Application.Command.MaintenanceRecordCommand;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.API.Application.CommandHandlers.MaintenanceRecordCommandHander
{
    /// <summary>
    /// 删除保养记录（单删）
    /// </summary>
    public class MaintenanceRecordDeleteCommandHandler : IRequestHandler<MaintenanceRecordDeleteCommand, int>
    {
        private readonly IMaintenanceRecordRepository _maintenanceRecordRepository;
        public MaintenanceRecordDeleteCommandHandler(IMaintenanceRecordRepository managementRecordRepository)
        {
            _maintenanceRecordRepository = managementRecordRepository;
        }
        public async Task<int> Handle(MaintenanceRecordDeleteCommand request, CancellationToken cancellationToken)
        {
            var delMain = await _maintenanceRecordRepository.GetModelAsync(request.MaintenanceId);
            delMain.IsDeleted = true;
           
            return await _maintenanceRecordRepository.UpdateAsync(delMain);
        }
    }
}
